package mystack;

import java.lang.reflect.Array;

/**
 * Created by Administrator on 2017/3/16.
 */
public class MySepStack<E> implements Mystack<E> {
    //定义一个变量maxsize
   private int maxsize;
    //定义一个数组
   private E[] date;
   //定义一个变量top
   private int top;

   public MySepStack(Class<E>type,int getSize){
       date=(E[]) Array.newInstance(type,getSize);
       maxsize=getSize;
       top=-1;
   }
    @Override
    public E push(E item) {
        if (!isFull()){
        date[++top]=item;
        return item;
    }else
        return null;
    }

    @Override
    public E pop() {
       E item=null;
       if (!isEmpty()){
           item=date[top--];
       }
        return item;
    }



    @Override
    public E peak() {
        E item=null;
        if (!isEmpty()){
            item =date[top];
        }
        return item;
    }

    @Override
    public boolean isEmpty() {
        if (top==-1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean isFull() {
       if (top==maxsize-1){
           return true;
       }else {
           return false;
       }
    }

    @Override
    public int getSize() {
        return top+1;
    }
}
